﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Context;
using Entities;
using WCF_ListenMusic.DataContract;
namespace WCF_ListenMusic.Services
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "CategoryService" in code, svc and config file together.
    public class CategoryService : ICategoryService
    {
        Context.Connect_DBDataContext context = new Context.Connect_DBDataContext();
        #region ICategoryService Members

        public List<Category> getAllCategory()
        {
            try
            {
                var q = from c in context.Categories
                        select c;
                return q.ToList();
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        #endregion


        public List<DataContract_Category> getAllCategory_byContry(int countryid)
        {
            try {
                var q = from c in context.Categories
                        where c.CountryID.Equals(countryid)
                        select new DataContract_Category() { 
                            CategoryID = Convert.ToInt32(c.CategoryID),
                            CategoryName = c.CategoryName,
                            CountryID = Convert.ToInt32(c.CountryID),
                            CountryName = c.Country.CountryName,
                        };
                return q.ToList();
            }
            catch (Exception ex) {
                throw new FaultException(ex.Message);
            }
        }
    }
}
